import { Body, Controller, Get, Param, Post, Query, Req, UseFilters, UseInterceptors } from '@nestjs/common';
import { VideoService } from './video.service';

//导入局部响应拦截器和局部异常拦截器
import { ResponseInterceptor } from 'src/response/response.interceptor';
import { ErrorfilterFilter } from 'src/errorfilter/errorfilter.filter';

//导入确定是否是公共接口
import { IsPublic } from 'src/is-public/is-public.decorator';

//验证数据
import { ValidatorpiePipe } from 'src/validatorpie/validatorpie.pipe';
import { VodVideoDto } from './dto/getvod-video.dto';
import { UploadVideoDto } from './dto/upload-video.dto';

@Controller({
  path:'video',
  version:'1'
})

@UseInterceptors(ResponseInterceptor)
@UseFilters(ErrorfilterFilter)
export class VideoController {
  constructor(private readonly videoService: VideoService) {}

  @Get('vod')
  getvod(@Query(ValidatorpiePipe) query:VodVideoDto){
    const {Title,FileName} = query
    return this.videoService.getvod(Title,FileName)
  }

  @Post('upload/:vodid')
  uploadvideo(@Param('vodid') vodid:string , @Body(ValidatorpiePipe) Body : UploadVideoDto ,@Req() req){
    const {Title} = Body
    const userid = req.session.userId
    return this.videoService.uploadvideo(vodid,userid,Title)
  }

  @Get('list')
  @IsPublic()
  async videoList(@Req() req, @Query() query){
    const { page = 1, pagesize = 10 } = query
    return await this.videoService.videoList(page,pagesize)
  }

  
  @Get('list/:vodid')
  @IsPublic()
  async videodetail(@Param() param){
    const { vodid } = param
    return await this.videoService.videodetail(vodid)
  }

  @Post('comment/:vodid')
  async comment(@Req() req,@Param() param,@Body() body){
    const { vodid } = param
    const {content = ''} = body
    const userid = req.session.userId
    return await this.videoService.comment(vodid,userid,content)
  }

  @Get('delcomment/:commentid')
  async delcomment(@Req() req,@Param() param){
    const { commentid } = param
    const userid = req.session.userId
    return await this.videoService.delcomment(commentid,userid)
  }


  @Get('comment/list/:videoid')
  @IsPublic()
  async commentList(@Req() req, @Query() query,@Param() param){
    const { page = 1, pagesize = 10 } = query
    const {videoid} = param
    return await this.videoService.commentList(page,pagesize,videoid)
  }


  @Get('like/:videoid')
  async likevideo(@Req() req,@Param() param){
    const { videoid } = param
    const userid = req.session.userId
    return await this.videoService.likevideo(videoid,userid)
  }


  @Get('dislike/:videoid')
  async dislikevideo(@Req() req,@Param() param){
    const { videoid } = param
    const userid = req.session.userId
    return await this.videoService.dislikevideo(videoid,userid)
  }


  @Get('likes')
  async likeList(@Req() req, @Query() query){
    const { page = 1, pagesize = 10 } = query
    const userid = req.session.userId
    return await this.videoService.likeList(page,pagesize,userid)
  }

  @Get('dislikes')
  async dislikeList(@Req() req, @Query() query){
    const { page = 1, pagesize = 10 } = query
    const userid = req.session.userId
    return await this.videoService.dislikeList(page,pagesize,userid)
  }

  @Get('topHot/:size')
  @IsPublic()
  async getHoc(@Param('size') size = 5){
    return await this.videoService.getHoc(size.toString())
  }
}
